import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import java.util.*;

public class EditUser extends HttpServlet{ 
 
   public void doPost(HttpServletRequest request, HttpServletResponse response)
                                   throws ServletException,IOException{
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();

			Connection conn = null;
			String url = Constants.DBURL;
			String dbName = Constants.DBName;
			String driver = Constants.DBDriver;
			String userName = Constants.DBUserName; 
			String password = Constants.DBUserPassword;

			out.println(request.getRequestURI());

			if(request.getParameter("id")!=null && request.getParameter("id")!="")
			{

                        int id = Integer.parseInt(request.getParameter("id").toString());
			String username = request.getParameter("username").toString();
			String first_name = request.getParameter("first_name").toString();
			String userpass = request.getParameter("password").toString();
			String last_name = request.getParameter("last_name").toString();
			String country = request.getParameter("country").toString();
		
			
			Statement stmt;
			try {
				Class.forName(driver).newInstance();
				conn = DriverManager.getConnection(url+dbName,userName,password);
				System.out.println("Connected to the database");
				
				ArrayList al=null;
				ArrayList userList =new ArrayList();
				String query = "update Users set UsersLogin='"+username+"',UsersPassword='"+userpass+"',"
                                        + "UsersName='"+first_name+"',UsersLastName='"+last_name+"',ContactCountryCode='"+country+"' where UsersId="+id;
				stmt = conn.createStatement();
            
			    int i = stmt.executeUpdate(query);
				System.out.println("query" + query);
				if(i>0)
				{
					response.sendRedirect("servletRecord");
				}
				conn.close();
				System.out.println("Disconnected from database");
			} catch (Exception e) {
			e.printStackTrace();
			}
		 }
	  }
}